package org.txazo.blog.commons.xml;

import java.util.HashSet;
import java.util.Set;

import org.txazo.blog.util.StringUtil;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

/**
 * XmlParser
 * 
 * @author Tu XiaoZhou
 * @since 2013-08-10
 * 
 */
public class XmlFilterParser extends DefaultHandler {

	/** 当前处理Tag */
	private String currentTag = null;
	private Set<String> uris = new HashSet<String>();

	@Override
	public void startElement(String uri, String localName, String qName,
			Attributes attributes) throws SAXException {
		currentTag = qName;
	}

	@Override
	public void endElement(String uri, String localName, String qName)
			throws SAXException {
		currentTag = null;
	}

	@Override
	public void characters(char[] ch, int start, int length)
			throws SAXException {
		if (currentTag != null && currentTag.equals("uri")) {
			String content = new String(ch, start, length);
			if (StringUtil.isNotEmpty(content)) {
				uris.add(content);
			}
		}
	}

	public Set<String> getUris() {
		return uris;
	}

}
